package com.tanhua.admin.task;

import com.tanhua.admin.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: cl
 * @Date: 2022/5/17 - 05 - 17
 * @Description:
 */

/**
 * 定时任务类(定时统计log日志数据)
 */
@Component
public class AnalysisTask {

    @Autowired
    private AnalysisService analysisService;


    //配置自动任务步骤(1:启动类加注解@EnableScheduling，
    //     2:方法上加注解@Scheduled( cron = "0/20 * * * * ? "))指定时间规则
    //@Scheduled(cron = "0/30 * * * * ? ")
    @Scheduled(cron = "0 0 0/1 * * ? ")//每小时执行一次
    public void analysis() throws ParseException {

        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("开始统计：" + time);
        //调logService完成日志统计
        analysisService.analysis();
        System.out.println("结束统计");
    }
}
